package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectCriteria;
import com.shrct.businessprocess.project.RCProjectStatus;
import com.shrct.businessprocess.project.RCProjectType;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCProjectCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProject> implements RCProjectCriteria {
  private String code;
  
  public String getCode() {
    return this.code;
  }
  
  public RCProjectCriteria setCode(final String code) {
    this.code = code;
    return this;			
    
  }
  
  private String name;
  
  public String getName() {
    return this.name;
  }
  
  public RCProjectCriteria setName(final String name) {
    this.name = name;
    return this;			
    
  }
  
  private RCEmployee saler;
  
  public RCEmployee getSaler() {
    return this.saler;
  }
  
  public RCProjectCriteria setSaler(final RCEmployee saler) {
    this.saler = saler;
    return this;			
    
  }
  
  private RCEmployee businessMan;
  
  public RCEmployee getBusinessMan() {
    return this.businessMan;
  }
  
  public RCProjectCriteria setBusinessMan(final RCEmployee businessMan) {
    this.businessMan = businessMan;
    return this;			
    
  }
  
  private RCEnterprise customer;
  
  public RCEnterprise getCustomer() {
    return this.customer;
  }
  
  public RCProjectCriteria setCustomer(final RCEnterprise customer) {
    this.customer = customer;
    return this;			
    
  }
  
  private RCEmployee owner;
  
  public RCEmployee getOwner() {
    return this.owner;
  }
  
  public RCProjectCriteria setOwner(final RCEmployee owner) {
    this.owner = owner;
    return this;			
    
  }
  
  private Boolean actualCostDirtyFlag;
  
  public Boolean getActualCostDirtyFlag() {
    return this.actualCostDirtyFlag;
  }
  
  public RCProjectCriteria setActualCostDirtyFlag(final Boolean actualCostDirtyFlag) {
    this.actualCostDirtyFlag = actualCostDirtyFlag;
    return this;			
    
  }
  
  private Boolean isPassed;
  
  public Boolean getIsPassed() {
    return this.isPassed;
  }
  
  public RCProjectCriteria setIsPassed(final Boolean isPassed) {
    this.isPassed = isPassed;
    return this;			
    
  }
  
  private Boolean isEarlyBuild;
  
  public Boolean getIsEarlyBuild() {
    return this.isEarlyBuild;
  }
  
  public RCProjectCriteria setIsEarlyBuild(final Boolean isEarlyBuild) {
    this.isEarlyBuild = isEarlyBuild;
    return this;			
    
  }
  
  private RCProjectType type;
  
  public RCProjectType getType() {
    return this.type;
  }
  
  public RCProjectCriteria setType(final RCProjectType type) {
    this.type = type;
    return this;			
    
  }
  
  private Boolean showActiveProjectOnly = Boolean.valueOf(false);
  
  public Boolean getShowActiveProjectOnly() {
    return this.showActiveProjectOnly;
  }
  
  public RCProjectCriteria setShowActiveProjectOnly(final Boolean showActiveProjectOnly) {
    this.showActiveProjectOnly = showActiveProjectOnly;
    return this;			
    
  }
  
  private RCProjectStatus creatingStatus = RCProjectStatus.creating;
  
  public RCProjectStatus getCreatingStatus() {
    return this.creatingStatus;
  }
  
  public RCProjectCriteria setCreatingStatus(final RCProjectStatus creatingStatus) {
    this.creatingStatus = creatingStatus;
    return this;			
    
  }
  
  private RCProjectStatus cancelStatus = RCProjectStatus.canceled;
  
  public RCProjectStatus getCancelStatus() {
    return this.cancelStatus;
  }
  
  public RCProjectCriteria setCancelStatus(final RCProjectStatus cancelStatus) {
    this.cancelStatus = cancelStatus;
    return this;			
    
  }
  
  public void postInitialize() {
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.project.impl.RCProjectImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode()) ){
    	hql += " and (this.code  LIKE :code)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getName()) ){
    	hql += " and (this.name  LIKE :name)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBusinessMan()) ){
    	hql += " and ((this.customer.businessMan) = (:businessMan))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer()) ){
    	hql += " and ((this.customer) = (:customer))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getActualCostDirtyFlag()) ){
    	hql += " and ((this.actualCostDirtyFlag) = (:actualCostDirtyFlag))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getShowActiveProjectOnly()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCreatingStatus()) ){
    	hql += " and (((:showActiveProjectOnly) = (false)) or ((this.status) <> (:creatingStatus)))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCancelStatus()) ){
    	hql += " and ((this.status) <> (:cancelStatus))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSaler()) ){
    	hql += " and (:saler  IN (select e1 from this.salers as s1 left join  s1.employee as e1   where  s1.active = 1      ))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner()) ){
    	hql += " and (:owner  IN (select e2 from this.salers as s2 left join  s2.employee as e2   where  s2.active = 1      ))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsPassed()) ){
    	hql += " and ((this.passed) = (:isPassed))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsEarlyBuild()) ){
    	hql += " and ((this.earlyBuildInfo.isEarlyBuild) = (:isEarlyBuild))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getType()) ){
    	hql += " and ((this.typeExtension.type) = (:type))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.code",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode())){
    	query.setParameter("code",getCode()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getName())){
    	query.setParameter("name",getName()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSaler())){
    	query.setParameter("saler",getSaler()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBusinessMan())){
    	query.setParameter("businessMan",getBusinessMan()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer())){
    	query.setParameter("customer",getCustomer()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner())){
    	query.setParameter("owner",getOwner()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getActualCostDirtyFlag())){
    	query.setParameter("actualCostDirtyFlag",getActualCostDirtyFlag()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsPassed())){
    	query.setParameter("isPassed",getIsPassed()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsEarlyBuild())){
    	query.setParameter("isEarlyBuild",getIsEarlyBuild()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getType())){
    	query.setParameter("type",getType()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getShowActiveProjectOnly())){
    	query.setParameter("showActiveProjectOnly",getShowActiveProjectOnly()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCreatingStatus())){
    	query.setParameter("creatingStatus",getCreatingStatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCancelStatus())){
    	query.setParameter("cancelStatus",getCancelStatus()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCProjectCriteriaImpl() {
    initOrderBys();
  }
}
